var showFlag1=0;
var showFlag2=0;
//弹窗控制
function dialog(flag,page)
{
			if (flag == 0) {
				if (map ==null) {
					   $("#mapdialog").show();
						initialize();
						countiesList("countiesIdForMap",searchStr.split("_")[1]);
				}else
				{
					  $("#mapdialog").show();
				}
			   }
			else if(flag==1){
					$("#loaddialog").show();
					countiesList("countiesId",searchStr.split("_")[1]);
				
			}else
			{
				$('#dialog').hide();$('#dialog').empty(); showFlag1=0;showFlag2=0;
				$("#citydialog").show();
			}
}
var searchStr="";
var address="";
//选择城市
function selectCity(id,addr,cityName)
{
	searchStr=id;
	address=addr;
	$("#citydialog").hide();
	$("#currentCity").html(cityName);
    setCookie("city", cityName, 0);
   if(map!=null)
   {
   	 countiesList("countiesIdForMap",searchStr.split("_")[1]);
   	 moveMap(cityName);
   }
}
//获得省列表
function provinceList(showId,callback)
{
	if($("#"+showId).val()==-1)
	{
		return false;
	}
	
	$.getJSON("dic!provinceList.action",function(data){
		var option="<option value='-1'>请选择</option>";
		for(var i=0;i<data.length;i++)
		{
			option+="<option value='"+data[i].id+"'>"+data[i].province+"</option>";
		}
		$("#"+showId).html(option);
		if(callback!=null)
		{
			callback();
		}
	});
}

//获得市列表
function cityList(showId,provinceId,callback)
{
	if(provinceId==-1)
	{
		return false;
	}
	$.getJSON("dic!cityList.action",{"provinceId":provinceId},function(data){
		var option="<option value='-1'>请选择</option>";
		for(var i=0;i<data.length;i++)
		{
			option+="<option value='"+data[i].id+"'>"+data[i].city+"</option>";
		}
		$("#"+showId).html(option);
		if(callback!=null)
		{
			callback();
		}
	});
}
//获得区列表
function countiesList(showId,cityId,callback)
{
	if(cityId==-1)
	{
		return false;
	}
	$.getJSON("dic!countiesList.action",{"cityId":cityId},function(data){
		var option="<option value='-1'>请选择</option>";
		for(var i=0;i<data.length;i++)
		{
			option+="<option value='"+data[i].id+"'>"+data[i].counties+"</option>";
		}
		
		$("#"+showId).html(option);
		
		if(callback!=null)
		{
			callback();
		}
	});
}
//获得路列表
function loadsList(showId,provinceId,cityId,countiesId,callback)
{
	if(countiesId==-1)
	{
		return false;
	}
	$.getJSON("dic!loadList.action",{"provinceId":provinceId,"cityId":cityId,"countiesId":countiesId},function(data){
		var option="<option value='-1'>请选择</option>";
		for(var i=0;i<data.length;i++)
		{
			option+="<option value='"+data[i].id+"'>"+data[i].loadName+"</option>";
		}
		$("#"+showId).html(option);
		if(callback!=null)
		{
			callback();
		}
	});
}
//获得路列表
function loadsListForIndex(showId,provinceId,cityId,countiesId,callback)
{
	if(countiesId==-1)
	{
		return false;
	}
	$.getJSON("dic!loadList.action",{"provinceId":provinceId,"cityId":cityId,"countiesId":countiesId},function(data){
		var option="";
		for(var i=0;i<data.length;i++)
		{
			option+='<li><a target="_blank" href="business!businessList.action?searchStr='+data[i].provinceId+'_'+data[i].cityId+'_'+data[i].countiesId+'_'+data[i].id+'">'+data[i].loadName+'</a></li>';
		}
		$("#"+showId).html(option);
		if(callback!=null)
		{
			callback();
		}
	});
}

//移动地图
function moveMap(keyword)
{
   
   var geocoder = new google.maps.Geocoder();
			geocoder.geocode( { 'address': keyword}, function(results, status) {
		      if (status == google.maps.GeocoderStatus.OK) {
		        map.setCenter(results[0].geometry.location);
		      } 
		    });
}

//取得cookie   
function getCookie(name) {   
 var nameEQ = name + "=";   
 var ca = document.cookie.split(';');    //把cookie分割成组   
 for(var i=0;i < ca.length;i++) {   
 var c = ca[i];                      //取得字符串   
 while (c.charAt(0)==' ') {          //判断一下字符串有没有前导空格   
 c = c.substring(1,c.length);      //有的话，从第二位开始取   
 }   
 if (c.indexOf(nameEQ) == 0) {       //如果含有我们要的name   
 return unescape(c.substring(nameEQ.length,c.length));    //解码并截取我们要值   
 }   
 }   
 return false;   
}   
  
//清除cookie   
function clearCookie(name) {   
 setCookie(name, "", -1);   
}   
  
//设置cookie   
function setCookie(name, value, seconds) {   
 seconds = seconds || 0;   //seconds有值就直接赋值，没有为0，这个根php不一样。   
 var expires = "";   
 if (seconds != 0 ) {      //设置cookie生存时间   
 var date = new Date();   
 date.setTime(date.getTime()+(seconds*1000));   
 expires = "; expires="+date.toGMTString();   
 }   
 document.cookie = name+"="+escape(value)+expires+"; path=/";   //转码并赋值   
}  
